package com.gdqy.FCS.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.gdqy.FCS.entity.FabricComponent;
import com.gdqy.FCS.service.FabricComponentService;


@Controller
@RequestMapping("fabricComponent")
public class FabricComponentController {

	@Autowired
	private FabricComponentService fabricComponentService;
	
	/**
	 * 
	 *作者：张伟键
	 *方法描述：管理字典数据
	 * @return
	 */
	@RequestMapping("admin_fabricComponent")
	public ModelAndView admin_fabricComponent() {
		ModelAndView modelAndView = new ModelAndView();
		List<FabricComponent> fabricComponents = fabricComponentService.selectAll();
		modelAndView.addObject("fabricComponents", fabricComponents);
		modelAndView.setViewName("path");
		return modelAndView;
	}
	/**
	 * 
	 *作者：张伟键
	 *方法描述：增加面料字典数据
	 * @param fabricComponent
	 * @return
	 */
	@RequestMapping("add_fabricComponent")
	public @ResponseBody String add_fabricComponent(FabricComponent fabricComponent) {
		String msg = "fail";
		int data = fabricComponentService.insert(fabricComponent);
		if(data > 0) {
			msg="success";
		}
		return msg;
	}
	
	@RequestMapping("get_FCByParent_code")
	public @ResponseBody List<FabricComponent> get_FCByParent_code(String parent_code) {
		List<FabricComponent> fabricComponents = fabricComponentService.selectClass(parent_code);
		return  fabricComponents;
	}
	/*
	 * 
	 * 获取面料成分列表
	 * 
	 * */
	@RequestMapping("getFabricComponentList")
	public ModelAndView getFabricComponentList() {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("fabic");
		
		List<FabricComponent> list=fabricComponentService.selectAll();
		modelAndView.addObject(list);
		
		return modelAndView;

	}

	/*
	 * 
	 * 通过id获取面料成分详情
	 * 
	 * */
	@RequestMapping("getFabricById")
	public ModelAndView getFabricById(String id) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("index");
		
		FabricComponent fabricComponent=fabricComponentService.selectById(Integer.parseInt(id));
		modelAndView.addObject(fabricComponent); 
		
		return modelAndView;

	}
	


}
